<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="util.*"%>
<%@page import="dal.*"%>
<%@ page import="model.*,java.util.*"%>
<%
	int idAgenda = MiscUtil.getIntUrlParam(request, "idAgenda");

	GenericDal<AgendaItemModel, AgendaItemModelExt> dal = new GenericDal<AgendaItemModel, AgendaItemModelExt>(
			new AgendaItemModel());
	AgendaItemModelExt queryCount = new AgendaItemModelExt();
	queryCount.setIdAgenda(idAgenda);
	
	int count = dal.count(queryCount);

	int pageIndex = 1;
	if (request.getParameter("pageIndex") != null
			&& !request.getParameter("pageIndex").isEmpty()) {
		try {
			pageIndex = Integer.parseInt(request
					.getParameter("pageIndex"));
		} catch (Exception e) {
		}
	}

	int pageSize = 20;
	if (request.getParameter("pageSize") != null
			&& !request.getParameter("pageSize").isEmpty()) {
		try {
			pageSize = Integer.parseInt(request
					.getParameter("pageSize"));
		} catch (Exception e) {
		}
	}

	int noOfPage = count / pageSize;
	if (count % pageSize > 0) {
		noOfPage++;
	}

	AgendaItemModelExt query = new AgendaItemModelExt();
	query.setIdAgenda(idAgenda);
	query.setLimit(pageSize);
	query.setOffset((pageIndex - 1) * pageSize);
	List<AgendaItemModel> list = dal.selectList(query);

	boolean embedded = false;
	if (request.getParameter("embedded") != null
			&& !request.getParameter("embedded").isEmpty()) {

		if (request.getParameter("embedded").equalsIgnoreCase("true")
				|| request.getParameter("embedded").equalsIgnoreCase(
						"1")) {
			embedded = true;
		}
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Agenda Item List</title>

<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/listForm.css" />


</head>
<body>
	<%
		if (!embedded)
		{
	%>
	<jsp:include page="menu.jsp"></jsp:include>
    <br />
	<%}%>
	<b>Number of Agenda Items: <%=count%></b>
	<br />
	<br />
	<%
		if(noOfPage>1)
		{
	%>
	<table class="tblPaging">
		<tr class="trPaging">
			<td class="tdPaging">				
                <%
					for (int i = 1; i <= noOfPage; i++) {
						if (i == pageIndex) {
				%> 
					<span class="lblPaging"><%=i%></span> 
				<%
				 		} else {
				 %> 
				 	<a class="hrefPaging" href="agendaItemList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
				<%
						}
					}
				%>
			</td>
		</tr>
	</table>
	<%} %>
    <br />
	<table class="tblList">
		<tr class="tblListHeader">			
            <th class="tdListHeader" colspan="2"></th>
<th class="thListHeader">Id</th>
<th class="thListHeader">Agenda</th>
<th class="thListHeader">Parent</th>
<th class="thListHeader">Name</th>
<th class="thListHeader">Description</th>
<th class="thListHeader">Remark</th>
<th class="thListHeader">Is Group</th>
<th class="thListHeader">Previous Item</th>
<th class="thListHeader">Start Time</th>
<th class="thListHeader">Duration</th>
<th class="thListHeader">Employee</th>
<th class="thListHeader">Company</th>
<th class="thListHeader">Sound</th>
<th class="thListHeader">Light</th>
<th class="thListHeader">Left Screen</th>
<th class="thListHeader">Right Screen</th>
<th class="thListHeader">Center Screen</th>
<!-- <th class="thListHeader">Code</th> -->
<!-- <th class="thListHeader">Id Type</th> -->
<th class="thListHeader">Status</th>
<!-- <th class="thListHeader">Notification</th> -->
<!-- <th class="thListHeader">Created</th> -->
<!-- <th class="thListHeader">Creator</th> -->
<!-- <th class="thListHeader">Updated</th> -->
<!-- <th class="thListHeader">Updator</th> -->
<!-- <th class="thListHeader">Deleted</th> -->
<!-- <th class="thListHeader">Deletion Time</th> -->

            <th class="tdListHeader"></th>
		</tr>

		<%
			int size = list.size();
			for (int i = 0; i < size; i++) {
				AgendaItemModel obj = list.get(i);
		%>

		<tr class="trListItem">
			<td class="tdListInt"><%=i + 1%></td>
			<td class="tdListHref Edit">
				<a href="agendaItem?mode=edit&id=<%=obj.getId()%>
">Edit</a>
			</td>
<td class="tdListInt"><%=obj.getIdToString()%></td>
<td class="tdListInt"><%=CacheUtil.getAgendaName(obj.getIdAgenda())%></td>
<td class="tdListInt"><%=CacheUtil.getAgendaItemName(obj.getIdParent())%></td>
<td class="tdListText"><%=obj.getName()%></td>
<td class="tdListTextarea"><%=obj.getDescription()%></td>
<td class="tdListTextarea"><%=obj.getRemark()%></td>
<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getIsGroup())%></td>
<td class="tdListInt"><%=CacheUtil.getAgendaItemName(obj.getIdPrevItem())%></td>
<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getStartTime())%></td>
<td class="tdListInt"><%=obj.getDurationToString()%></td>
<td class="tdListInt"><%=CacheUtil.getEmployeeName(obj.getIdEmployee())%></td>
<td class="tdListInt"><%=CacheUtil.getCompanyName(obj.getIdCompany())%></td>
<td class="tdListTextarea"><%=obj.getSound()%></td>
<td class="tdListTextarea"><%=obj.getLight()%></td>
<td class="tdListTextarea"><%=obj.getLeftScreen()%></td>
<td class="tdListTextarea"><%=obj.getRightScreen()%></td>
<td class="tdListTextarea"><%=obj.getCenterScreen()%></td>
<%-- <td class="tdListText"><%=obj.getCodeToString()%></td> --%>
<%-- <td class="tdListInt"><%=obj.getIdTypeToString()%></td> --%>
<td class="tdListInt"><%=StringUtil.getAgendaItemStatus(obj.getStatus())%></td>
<%-- <td class="tdListInt"><%=obj.getNotificationToString()%></td> --%>
<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getCreated())%></td> --%>
<%-- <td class="tdListInt"><%=obj.getCreatorToString()%></td> --%>
<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getUpdated())%></td> --%>
<%-- <td class="tdListInt"><%=obj.getUpdatorToString()%></td> --%>
<%-- <td class="tdListBool"><%=HtmlUtil.genHtml(obj.getDeleted())%></td> --%>
<%-- <td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getDeletionTime())%></td> --%>

            <td class="tdListHref">
				<a href="agendaItem?mode=delete&id=<%=obj.getId()%>
">Delete</a>
			</td>
		</tr>
		<%
			}
		%>
	</table>
    <br />
    <%
    	if(noOfPage>1)
    	{
    %>
    <table class="tblPaging">
		<tr class="trPaging">
			<td class="tdPaging">				
                <%
					for (int i = 1; i <= noOfPage; i++) {
						if (i == pageIndex) {
				%> 
					<span class="lblPaging"><%=i%></span> 
				<%
				 		} else {
				 %> 
				 	<a class="hrefPaging" href="agendaItemList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
				<%
						}
					}
				%>
			</td>
		</tr>
	</table>
	<%} %>
</body>
</html>